package ups.SOAP;

import java.net.URL;
import java.net.HttpURLConnection;
import ups.SOAP.Message;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.File;
public class Client {
	public Client() {
		return;
	}
	
	public boolean sendMessage( URL dst, Message m ) {
		try {
			HttpURLConnection conn = (HttpURLConnection)dst.openConnection();
			
			conn.setDoInput	( true );
			conn.setDoOutput( true );
			conn.setRequestMethod("POST");
			conn.setRequestProperty("SOAPAction", "http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay");
			//conn.connect();
			
			//System.out.println( conn.getContent().toString());
			
			FileInputStream fileIn = new FileInputStream( new File("/Users/scanfield/Documents/School/Summer07Project/request.txt") );
			
			OutputStream out = conn.getOutputStream();
			
			
			
			int inputValue = 0;
			while( inputValue != -1 ) {
				inputValue = fileIn.read();
				if( inputValue != -1 ) { 
					System.out.printf( "%c", inputValue );
					out.write( inputValue );
				}
			}
			out.close();
			System.out.println("\n");
			
			//conn.connect();
			
			System.out.println("HTTP Status " + conn.getResponseCode() + "\n");
			
			int val = 0;
			while(  val != -1 ) {
				val = ((InputStream)conn.getContent()).read();
					if( val != -1 ) {
						System.out.printf( "%c", val );
				}
			}
			System.out.println();
			
			
			
		} catch (Exception e ) {
			System.out.println( e.getMessage() );
			e.printStackTrace();
		}
		return true;
	}
}
